R: Kolmogorov | 您所在的位置:网站首页 › kolmogorov-smirnov test › R: Kolmogorov |
ks.test {stats}R Documentation
Kolmogorov-Smirnov Tests
Description
Perform a one- or two-sample Kolmogorov-Smirnov test. Usage ks.test(x, ...) ## Default S3 method: ks.test(x, y, ..., alternative = c("two.sided", "less", "greater"), exact = NULL, simulate.p.value = FALSE, B = 2000) ## S3 method for class 'formula' ks.test(formula, data, subset, na.action, ...) Arguments xa numeric vector of data values. yeither a numeric vector of data values, or a character string naming a cumulative distribution function or an actual cumulative distribution function such as pnorm. Only continuous CDFs are valid. ...for the default method, parameters of the distribution specified (as a character string) by y. Otherwise, further arguments to be passed to or from methods. alternativeindicates the alternative hypothesis and must be one of "two.sided" (default), "less", or "greater". You can specify just the initial letter of the value, but the argument name must be given in full. See ‘Details’ for the meanings of the possible values. exactNULL or a logical indicating whether an exact p-value should be computed. See ‘Details’ for the meaning of NULL. simulate.p.valuea logical indicating whether to compute p-values by Monte Carlo simulation. (Ignored for the one-sample test.) Ban integer specifying the number of replicates used in the Monte Carlo test. formulaa formula of the form lhs ~ rhs where lhs is a numeric variable giving the data values and rhs either 1 for a one-sample test or a factor with two levels giving the corresponding groups for a two-sample test. dataan optional matrix or data frame (or similar: see model.frame) containing the variables in the formula formula. By default the variables are taken from environment(formula). subsetan optional vector specifying a subset of observations to be used. na.actiona function which indicates what should happen when the data contain NAs. Defaults to getOption("na.action"). DetailsIf y is numeric, a two-sample (Smirnov) test of the null hypothesis that x and y were drawn from the same distribution is performed. Alternatively, y can be a character string naming a continuous (cumulative) distribution function, or such a function. In this case, a one-sample (Kolmogorov) test is carried out of the null that the distribution function which generated x is distribution y with parameters specified by .... The presence of ties always generates a warning in the one-sample case, as continuous distributions do not generate them. If the ties arose from rounding the tests may be approximately valid, but even modest amounts of rounding can have a significant effect on the calculated statistic. Missing values are silently omitted from x and (in the two-sample case) y. The possible values "two.sided", "less" and "greater" of alternative specify the null hypothesis that the true cumulative distribution function (CDF) of x is equal to, not less than or not greater than the hypothesized CDF (one-sample case) or the CDF of y (two-sample case), respectively. The test compares the CDFs taking their maximal difference as test statistic, with the statistic in the "greater" alternative being D^+ = \max_u [ F_x(u) - F_y(u) ]. Thus in the two-sample case alternative = "greater" includes distributions for which x is stochastically smaller than y (the CDF of x lies above and hence to the left of that for y), in contrast to t.test or wilcox.test. Exact p-values are not available for the one-sample case in the presence of ties. If exact = NULL (the default), an exact p-value is computed if the sample size is less than 100 in the one-sample case and there are no ties, and if the product of the sample sizes is less than 10000 in the two-sample case, with or without ties (using the algorithm described in Schr枚er and Trenkler (1995)). Otherwise, the p-value is computed via Monte Carlo simulation in the two-sample case if simulate.p.value is TRUE, or else asymptotic distributions are used whose approximations may be inaccurate in small samples. In the one-sample two-sided case, exact p-values are obtained as described in Marsaglia, Tsang & Wang (2003) (but not using the optional approximation in the right tail, so this can be slow for small p-values). The formula of Birnbaum & Tingey (1951) is used for the one-sample one-sided case. If a one-sample test is used, the parameters specified in ... must be pre-specified and not estimated from the data. There is some more refined distribution theory for the KS test with estimated parameters (see Durbin, 1973), but that is not implemented in ks.test. ValueA list inheriting from classes "ks.test" and "htest" containing the following components: statisticthe value of the test statistic. p.valuethe p-value of the test. alternativea character string describing the alternative hypothesis. methoda character string indicating what type of test was performed. data.namea character string giving the name(s) of the data. SourceThe two-sided one-sample distribution comes via Marsaglia, Tsang and Wang (2003). Exact distributions for the two-sample (Smirnov) test are computed by the algorithm proposed by Schr枚er (1991) and Schr枚er & Trenkler (1995) using numerical improvements along the lines of Viehmann (2021). ReferencesZ. W. Birnbaum and Fred H. Tingey (1951). One-sided confidence contours for probability distribution functions. The Annals of Mathematical Statistics, 22/4, 592–596. doi:10.1214/aoms/1177729550. William J. Conover (1971). Practical Nonparametric Statistics. New York: John Wiley & Sons. Pages 295–301 (one-sample Kolmogorov test), 309–314 (two-sample Smirnov test). Durbin, J. (1973). Distribution theory for tests based on the sample distribution function. SIAM. W. Feller (1948). On the Kolmogorov-Smirnov limit theorems for empirical distributions. The Annals of Mathematical Statistics, 19(2), 177–189. doi:10.1214/aoms/1177730243. George Marsaglia, Wai Wan Tsang and Jingbo Wang (2003). Evaluating Kolmogorov's distribution. Journal of Statistical Software, 8/18. doi:10.18637/jss.v008.i18. Gunar Schr枚er (1991). Computergest眉tzte statistische Inferenz am Beispiel der Kolmogorov-Smirnov Tests. Diplomarbeit Universit盲t Osnabr眉ck. Gunar Schr枚er and Dietrich Trenkler (1995). Exact and Randomization Distributions of Kolmogorov-Smirnov Tests for Two or Three Samples. Computational Statistics & Data Analysis, 20(2), 185–202. doi:10.1016/0167-9473(94)00040-P. Thomas Viehmann (2021). Numerically more stable computation of the p-values for the two-sample Kolmogorov-Smirnov test. https://arxiv.org/abs/2102.08037. See Alsopsmirnov. shapiro.test which performs the Shapiro-Wilk test for normality. Examples require("graphics") x |
CopyRight 2018-2019 实验室设备网 版权所有 |